//
//  TMLoader.h
//  
//
//  Created by 周良飞 on 16/11/23.
//  Copyright (c) 2016年 e360. All rights reserved.
//
#import <UIKit/UIKit.h>


//
#pragma mark-
#pragma mark TMLoaderDelegate
@class TMLoader;
@protocol TMLoaderDelegate <NSObject>
@optional
-(void)openLoader:(TMLoader *)loader;
-(void)completeLoader:(TMLoader *)loader error:(NSError*)error;
-(void)progressLoader:(TMLoader *)loader bytesLoaded:(unsigned long long)bytesLoaded bytesTotal:(unsigned long long)bytesTotal;
@end


//
#pragma mark-
#pragma mark TMLoader
@interface TMLoader : NSObject
@property(nonatomic, copy) NSString *file;
@property(nonatomic, strong) NSURLRequest *request;
@property(nonatomic, readonly) NSString *filePath;
@property(nonatomic, readonly) NSData *data;
//delegate:[nil=同步,其他=异步],cache:[NO=网络优先，YES=本地优先]
-(instancetype)initWithDelegate:(id<TMLoaderDelegate>)delegate cache:(BOOL)cache;
-(void)load:(NSURLRequest*)request file:(NSString*)file;
-(void)close;
@end


//
#pragma mark-
#pragma mark NSURLRequest
@interface NSURLRequest (TMLoader)
+(NSURLRequest*)requestWithURL:(NSURL*)url post:(id)post;
@end


//
#pragma mark-
#pragma mark NSString
@interface NSString (TMLoader)
-(NSString*)md5;
@end


//
#pragma mark-
#pragma mark UIDevice
UIKIT_EXTERN NSString *const UIDeviceNetWorkDidChangeNotification;
typedef NS_ENUM(NSInteger, UIDeviceNetwork) {
    UIDeviceNetworkNone,
    UIDeviceNetworkWiFi,
    UIDeviceNetworkWWAN
};
@interface UIDevice (TMLoader)
@property(nonatomic, readonly) UIDeviceNetwork network;
@end


//
#pragma mark-
#pragma mark UIImageView
@interface UIImageView (TMLoader) <TMLoaderDelegate>
@property(nonatomic, copy) NSString *src;
-(void)load:(NSString*)file base:(NSString*)base complete:(void (^)(id target))complete;
-(void)load:(NSString*)file base:(NSString*)base;
@end
